package titan.wizards.newPackagedSection;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

/**
 * Class associated with the popupMenu for the folder
 * Start the wizard in the run method (just an example [not used])
 */
public class SectionAction implements IObjectActionDelegate 
{
	IWorkbenchPart part;
	ISelection selection;

	/**
	 * {@inheritDoc}
	 */
	public void setActivePart(IAction action, IWorkbenchPart part) {
			this.part = part;
	}

	/**
	 * {@inheritDoc}
	 */
	public void run(IAction action) {

		// Instantiates and initializes the wizard
		SectionWizard wizard = new SectionWizard();
		if ((selection instanceof IStructuredSelection) || (selection == null))
			wizard.init(part.getSite().getWorkbenchWindow().getWorkbench(), (IStructuredSelection)selection);

		// Instantiates the wizard container with the wizard and opens it
		WizardDialog dialog = new WizardDialog( part.getSite().getShell(), wizard);
		dialog.create();
		dialog.open();
	}

	/**
	 * {@inheritDoc}
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		this.selection = selection;
	}
}